<?




//同意加上and，然后去除左边的and就可以了。
if($_REQUEST['select_keywords'])
{
    $keywords=" and (name like '%".$_REQUEST['select_keywords']."%'  or remark like '%".$_REQUEST['select_keywords']."%' or phone like '%".$_REQUEST['select_keywords']."%'  )";
    $keywords_url="&select_keywords=".$_REQUEST['select_keywords'];
}
else
{
    $keywords="";
    $keywords_url="";
}



if(($_REQUEST['select_paystatus'])&&($_REQUEST['select_paystatus']!="全部"))
{
    $paystatus=" and status = '".$_REQUEST['select_paystatus']."'";
    $paystatus_url="&select_paystatus=".$_REQUEST['select_paystatus'];
}
else
{
    $paystatus="";
    $paystatus_url="";
}




if(($_REQUEST['select_graduate'])&&($_REQUEST['select_graduate']!="全部"))
{
    $graduate=" and graduate = '".$_REQUEST['select_graduate']."'";
    $graduate_url="&select_graduate=".$_REQUEST['select_graduate'];
}
else
{
    $graduate="";
    $graduate_url="";
}





if(($_REQUEST['select_departmentid'])&&($_REQUEST['select_departmentid']!="全部"))
{
    $departmentid=" and departmentid = '".$_REQUEST['select_departmentid']."'";
    $departmentid_url="&select_departmentid=".$_REQUEST['select_departmentid'];
}
else
{
    $departmentid="";
    $departmentid_url="";
}





if(($_REQUEST['select_license'])&&($_REQUEST['select_license']!="全部"))
{
    $license=" and license = '".$_REQUEST['select_license']."'";
    $license_url="&select_license=".$_REQUEST['select_license'];
}
else
{
    $license="";
    $license_url="";
}






//筛选申请修改的数据
if($_REQUEST['select_apply'])
{


    $applymodify=select_lines_all_items($table_Prefix."member","","applystatus='申请修改'","");

    $applymodify_sid= two_d_array_item_in_one_d_array($applymodify,"sid");

    $applymodify_values_str="'".implode("','",$applymodify_sid)."'";

    $applymodify_str="and nid in (".$applymodify_values_str.")";

    $select_apply_url="&select_apply=applystatus";
}
else
{
    $select_apply="";
    $select_apply_url="";
}







if($_REQUEST['select_startday'])
{
    $start_date=$_REQUEST['select_startday']." 00:00:00";
    $start_date_str=" and applydate > '".$start_date."'";
    $start_date_url="&select_startday=".$_REQUEST['select_startday'];
}
else
{
    $start_date_str="";
    $start_date_url="";
}




if($_REQUEST['select_endday'])
{
    $end_date=$_REQUEST['select_endday']." 23:59:59";
    $end_date_str=" and applydate < '".$end_date."'";
    $end_date_url="&select_endday=".$_REQUEST['select_endday'];
}
else
{
    $end_date_str="";
    $end_date_url="";
}



//如果需要查找即将过期的学生。

$student_expire_nid_list=two_d_array_item_in_one_d_array($student_expire_list,"nid");
$student_expire_nid_list_str=implode("','",$student_expire_nid_list);

if($_REQUEST['select_expire'])
{
    $expire=" and nid in('".$student_expire_nid_list_str."')";
    $expire_url="&select_expire=".$_REQUEST['select_expire'];
}
else
{
    $expire="";
    $expire_url="";
}






if($sortorder)
{
    $sortorder="order by ".$sortorder;
}
else
{
    $sortorder="";
}







//生成翻页用连接地址。

//select_keywords=&select_paystatus=全部&select_graduate=全部&select_departmentid=7&select_license=全部&select_startday=2017-06-01&select_endday=2017-06-20
//select_keywords=欠费&select_start_date=2017-06-21&select_end_date=2017-06-18


$pagenumber_url = "&nowpageid=" . $_REQUEST['nowpageid'];
$sortby_url     = "&sortby=" . $_REQUEST['sortby'];
$navitemed_url  = "&nav-itemed=" . $_REQUEST['nav-itemed'];
$system_part    = "&system_part=" . $_REQUEST['system_part'];
$term_nid       = "&term_nid=" . $_REQUEST['nid'];





$url_str=$keywords_url.$paystatus_url.$graduate_url.$departmentid_url.$license_url.$start_date_url.$end_date_url.$expire_url.$navitemed_url;



$select_str=$keywords.$paystatus.$graduate.$departmentid.$license.$start_date_str.$end_date_str.$applymodify_str.$expire;




//"ltrim函数处理出现bug，改用substr"
//echo $select_str=ltrim($select_str,' and');



//echo  $select_str=substr($select_str,4);


//接收传递过来的分类id
$trans_nid   = addslashes($_REQUEST ['nid']);

 

//分类id存在，则说明要搜索板块中某一个分类的产品。
if ($trans_nid)
{
    $condition="and departmentid = '".$trans_nid."'";
}

//设置需要搜索的表格的前缀后缀
    $table_Suffix = $plate['table_Suffix'];
    $table = $table_Prefix . $table_Suffix;
    $sqlstr="SELECT COUNT(nid) FROM $table    where nid >1  $select_str";
    $query = mysql_query($sqlstr);
    $sum = mysql_result($query, 0);

?>











<?php
//设置翻页代码相关内容

$nowpageid = 1;
$detailnum = $plate['page_list_num']; //每页显示多少个产品


if ($_REQUEST ['nowpageid']) {
    $nowpageid = $_REQUEST ['nowpageid'];
} else {
    $nowpageid = 1;
}


//计算一下结果，从那条数据开始显示
$detailstar = ($nowpageid - 1) * $detailnum;


if ($sum) {

    if ($sum < $detailnum) {
        $page_count = 1;
        $detailnum = $sum;
    } //如果总数据量小于$Pagenum,（pagenum作为每页显示数据的条数，）那么只有一页,而pagenum也更改为sum 


    else if ($sum % $detailnum) {
        $page_count = (int)($sum / $detailnum) + 1;
    }
    //取总数据量除以每页数的余数 
    //如果有余数，则页数等于总数据量除以每页数的结果取整再加一


    else {
        $page_count = $sum / $detailnum;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果 

} else {
    $page_count = 0;
    $detailnum = 0;
}


$lastpage = $page_count;
$prepage = $nowpageid - 1;
$nextpage = $nowpageid + 1;


if ($nowpageid == 1) {
    $prepage = 1;
}


if ($nowpageid == $page_count) {

    if ($sum <= $detailnum) //总数数据少于每页显示数目，就把循环改成总数数目
    {
        $detailnum = $sum;
        $nextpage = $nowpageid;
    } else {
        $nextpage = $nowpageid;
        $detailnum = fmod($sum, $detailnum);
        if ($detailnum == 0) //这个if是因为当数据正好30条，能除尽的话，最后一页就会因为fmod能整除的缘故，最后一页不显示数据
        {
            $detailnum = $plate['page_list_num'];
        }
    }
    //如果现在页数等于总页数（总页数上面求出，最后一页不够循环数的时候），那么最后一页的detailnum就会等于余下数据(不足一页)的数目.

}

?>






 
<?
//设置需要搜索的表格的排序项和升降项
$sort_by = "nid";
$sort_order = "desc";
//设置需要搜索的表格的排序项和升降项


if ($_REQUEST ['sortby']) {
    $sort_by = $_REQUEST ['sortby'];
}


if ($_REQUEST ['sortorder']) {
    $sort_order = $_REQUEST ['sortorder'];
}




 $sqlstr="select * from $table where nid >1 $select_str ORDER BY $sort_by $sort_order  limit $detailstar , $detailnum";


	$result = mysql_query($sqlstr) or die ("error:".mysql_error());


while ($row = mysql_fetch_array($result)) {
    $detail[]           = $row;
}

mysql_close($con);

?>








